#ifndef _HELIX_GLSL_SHADER_H_
#define _HELIX_GLSL_SHADER_H_


#include "../../../HObject.h"
#include "../OpenGLSupport.h"
#include "../OpenGLExt.h"

#include <map>
#include <string>

using namespace std;

namespace helix
{

	/**
	*	The GLSLShader is a helper class for using GLSL shaders in your OpenGL application.
	*/
	class MY_CLASS GLSLShader : public HObject
	{
	private :
		GLhandleARB vertexShader;
		GLhandleARB fragmentShader;
		GLhandleARB program;

		map<string,GLint> uniforms;
		map<string,GLint> attributes;

		static const unsigned int INFO_LOG_SIZE = 256;
		static const unsigned int UNIFORM_VARIABLE = 0;
		static const unsigned int ATTRIBUTE_VARIABLE = 1;

		void compileShader(GLhandleARB, const char* shaderSource);
		void logInfoLog(GLhandleARB object);

		GLint getVariableLocation(unsigned int type,const char *name);
	public:

		/**
		*	Constructor for setting up, compiling, and using a GLSL shader program.
		*	\param vertexShaderSource A string representing the source for the vertex shader.
		*	\param fragmentShaderSource A string representing the source for the fragment shader.
		*/
		GLSLShader(const char* vertexShaderSource, const char* fragmentShaderSource);

		/**
		*	Releases the OpenGL shader objects 
		*/
		virtual ~GLSLShader();

		/**
		*	Allows you to "turn on" or "turn off" the shader.  This allows you to control whether or
		*	not the shader is used for rendering.
		*	\param use If true, the shader will be used for rendering, if false, the default OpenGL rendering
		*	pipeline will be used.
		*/
		void useShader(bool use);


		/**
		*	Assign a uniform float variable (or vector) in the shader
		*	\param name The name of the uniform variable in the shader
		*	\param count the size of the uniform array (1 to 4 floats)
		*	\param value array of floats that contain the values to set
		*/
		void assignUniformF(const char* name, unsigned int count, float *value);

		/**
		*	Assign a uniform int variable (or vector) in the shader
		*	\param name The name of the uniform variable in the shader
		*	\param count the size of the uniform array (1 to 4 floats)
		*	\param value array of ints that contain the values to set
		*/
		void assignUniformI(const char* name, unsigned int count, int *value);

		/**
		*	Assign a texture sampler to a specific texture unit
		*	\param name The name of the sampler variable in the shader
		*	\param textureUnir The texure unit to assign to this sampler.  Zero is the first unit.
		*/
		void assignTextureSampler(const char* name, int textureUnit);

	};
	
}


#endif